<?php

include '../app/common.php';
include '../check.php';

if (!isset($_REQUEST['id']) || !is_numeric($_REQUEST['id'])) {
    exit;
}
$id = $_REQUEST['id'];
$data = $ADDB->query("SELECT * FROM ad_small WHERE id='{$id}'  limit 1")->fetch();

?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改页面</title>
    <link rel="stylesheet" href="../component/pear/css/pear.css"/>
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <input type="hidden" name="id" value="<?php echo $id; ?>">
            <div class="layui-form-item">
                <label class="layui-form-label">广告位别名</label>
                <div class="layui-input-block">
                    <input type="text" name="nickname" value="<?php echo $data['nickname'] ?>" lay-verify="required"
                           autocomplete="off"
                           placeholder="请输入广告位别名" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">排序</label>
                <div class="layui-input-block">
                    <input type="text" name="sort" value="<?php echo $data['sort'] ?>" lay-verify="required"
                           autocomplete="off"
                           placeholder="请输入广告位排序" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">价格</label>
                <div class="layui-input-block">
                    <input type="text" name="price" value="<?php echo $data['price'] ?>" lay-verify="required"
                           autocomplete="off"
                           placeholder="请输入广告位价格" class="layui-input">
                </div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">招商图片</label>
                <div class="layui-input-block">
                    <input type="text" name="default_img"   lay-verify="required"
                           autocomplete="off" value="<?php echo $data['default_img'] ?>" placeholder="请输入招商图片地址" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">广告商QQ</label>
                <div class="layui-input-block">
                    <input type="text" name="ad_qq" lay-verify="ad_qq" autocomplete="off"
                           value="<?php echo $data['ad_qq'] ?>" placeholder="请输入广告商QQ"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">图片地址</label>
                <div class="layui-input-block">
                    <input type="text" name="ad_img" value="<?php echo $data['ad_img'] ?>" lay-verify="required"
                           autocomplete="off" placeholder="请输入广告图片地址" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">广告链接</label>
                <div class="layui-input-block">
                    <input type="text" name="ad_url" value="<?php echo $data['ad_url'] ?>" lay-verify="required"
                           autocomplete="off"
                           placeholder="请输入广告链接" class="layui-input">
                </div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">开始时间</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" id="create_time-start" name="start_time"
                           value="<?php echo $data['start_time'] ?>" lay-verify="required"
                           placeholder="请输入开始时间" autocomplete="off">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">结束时间</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" id="create_time-end" value="<?php echo $data['end_time'] ?>"
                           name="end_time" lay-verify="required"
                           placeholder="请输入结束时间" autocomplete="off">
                </div>
            </div>


        </div>
    </div>
    <div class="bottom">
        <div class="" align="center">
            <button type="submit" class="pear-btn pear-btn-md pear-btn-primary" lay-submit=""  lay-filter="user-save" >
                <i class="layui-icon layui-icon-release"></i>
                提交数据
            </button>

            <button  class="pear-btn pear-btn-md layui-btn-primary" lay-filter="formClose" onclick="formClose();">
                <i class="layui-icon layui-icon-close"></i>
                关闭页面
            </button>
        </div>
    </div>
</form>
<script src="../component/layui/layui.js"></script>
<script src="../component/pear/pear.js"></script>
<script src="../component/pear/close.js"></script>

<script>
    layui.use(['form', 'jquery', 'laydate'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let laydate = layui.laydate;


        laydate.render({
            elem: "#create_time-start"
        });
        laydate.render({
            elem: "#create_time-end"
        })

        form.on('submit(user-save)', function (data) {
            $.ajax({
                url: 'ajax.class.php?act=editSmallAd',
                data: JSON.stringify(data.field),
                dataType: 'json',
                content_type: 'application/x-www-form-urlencoded',
                type: 'post',
                success: function (result) {
                    if (result.code == 1) {
                        layer.msg(result.msg, {
                            icon: 1,
                            time: 1000
                        }, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window
                                .name)); //关闭当前页
                            parent.layui.table.reload("user-table");
                        });
                    } else {
                        layer.msg(result.msg, {
                            icon: 2,
                            time: 1000
                        });
                    }
                }
            })
            return false;
        });
    })
</script>
<script>
</script>
</body>
</html>
